package io.hxci.modules.tea.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.hxci.common.annotation.DataFilter;
import io.hxci.common.utils.Constant;
import io.hxci.common.utils.PageUtils;
import io.hxci.common.utils.Query;
import io.hxci.modules.sys.entity.SysDeptEntity;
import io.hxci.modules.sys.entity.SysUserEntity;
import io.hxci.modules.sys.service.SysDeptService;
import io.hxci.modules.sys.service.SysUserService;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.hxci.modules.tea.dao.TeaTreatiseMapper;
import io.hxci.modules.tea.domain.TeaTreatise;
import io.hxci.modules.tea.service.TeaTreatiseService;
@Service
public class TeaTreatiseServiceImpl extends ServiceImpl<TeaTreatiseMapper, TeaTreatise> implements TeaTreatiseService{

    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private SysUserService sysUserService;

    @Override
    @DataFilter(subDept = true, user = true, tableAlias = "u")
    public PageUtils queryPage(Map<String, Object> params) {
        String sql_filter = (String)params.get(Constant.SQL_FILTER);
        String username = (String)params.get("username");
        String deptId = (String)params.get("deptId");
        IPage<TeaTreatise> page = new Query<TeaTreatise>().getPage(params);
        page.setRecords(this.baseMapper.queryPage(page,sql_filter,username,deptId));
        return new PageUtils(page);
    }

   /* @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String)params.get("name");
        IPage<TeaTreatise> page = this.page(
                new Query<TeaTreatise>().getPage(params),
                new QueryWrapper<TeaTreatise>().like(StringUtils.isNotBlank(key),"name", key)
        );
        for(TeaTreatise teaTreatise : page.getRecords()){
            SysUserEntity sysUserEntity = sysUserService.getById(teaTreatise.getUserId());
            teaTreatise.setUsername(sysUserEntity.getUsername());
            SysDeptEntity sysDeptEntity = sysDeptService.getById(sysUserEntity.getDeptId());
            teaTreatise.setDeptname(sysDeptEntity.getName());
        }
        return new PageUtils(page);
    }*/
}
